<script setup lang='ts'>
import { ref, watch } from 'vue'
const props = withDefaults(defineProps<{
    rotationValue?: [number, number, number],
    defaultValue?: any,
    readonly?: boolean
}>(), { rotationValue: () => [0, 0, 0] })

const emits = defineEmits([
    "update:rotationValue"
]);
const longitude = ref()
const latitude = ref()
const height = ref()
const mouseFlag = ref(false)
watch(() => props.rotationValue, (val) => {
    mouseFlag.value = false
    longitude.value = val[0].toFixed(2)
    latitude.value = val[1].toFixed(2)
    height.value = val[2].toFixed(2)
}, { immediate: true })
const update = (e: any, numberValues: [number, number, number] | undefined, num: number) => {
    if (numberValues === undefined) return
    let numberArr = [...numberValues]
    numberArr[num] = Number(e.target.value)
    emits("update:rotationValue", numberArr)
}
const resetDefult = () => {
    if (props.defaultValue) {
        emits('update:rotationValue', props.defaultValue)
    }
}
</script>

<template>
    <div class="position">
        <div class="position_name">{{ '姿态角度' }}</div>
        <div class="position_type">
            <div class="input2" style="margin-bottom: 5px;">
                <!-- <label for=""> {{ '偏航角' }}</label> -->
                <div class="input2_index">
                    <div class="input2_index_div"><input type="number" class="input_number" :value="longitude"
                            @blur="update($event, rotationValue, 0)" @keydown.enter="update($event, rotationValue, 0)"
                            step="0.01" placeholder="请输入偏航角" /><span>h</span></div>

                </div>
            </div>
            <div class="input2" style="margin-bottom: 5px;">
                <!-- <label for=""> {{ '俯仰角' }}</label> -->
                <div class="input2_index">
                    <div class="input2_index_div"> <input type="number" class="input_number" :value="latitude"
                            @blur="update($event, rotationValue, 1)" @keydown.enter="update($event, rotationValue, 1)"
                            step="0.01" placeholder="请输入俯仰角" /><span>p</span></div>

                </div>
            </div>
            <div class="input2">
                <!-- <label for=""> {{ '翻滚角' }}</label> -->
                <div class="input2_index">
                    <div class="input2_index_div">
                        <input type="number" class="input_number" :value="height"
                            @blur="update($event, rotationValue, 2)" @keydown.enter="update($event, rotationValue, 2)"
                            step="0.01" placeholder="请输入翻滚角" /><span>r</span>
                    </div>

                </div>

            </div>
        </div>
        <div class="checkbox1">
            <div v-if="!readonly && defaultValue !== undefined && ((rotationValue[0] !== defaultValue[0]) || (rotationValue[1] !== defaultValue[1]) || (rotationValue[2] !== defaultValue[2]))"
                class="checkbox" @click.stop.prevent="resetDefult" @mouseover="mouseFlag = true"
                @mouseout="mouseFlag = false">
                <es-icon :name="'huaban'" :color="mouseFlag ? 'rgba(230, 230, 230, 1)' : 'rgba(230, 230, 230, 0.4)'"
                    :size="14" />
            </div>
        </div>
    </div>


</template>

<style scoped>
.position {
    width: 100%;
    border-top: 1px solid #111111;
    border-bottom: 1px solid #111111;
    padding-top: 10px;
    padding-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.position_name {
    width: 70px;
    line-height: 26px;
}

.position_type {
    flex: 1;
    display: flex;
    flex-direction: column;
    /* border: 2px solid rgba(127, 127, 127, 0.219); */
    box-sizing: border-box;
    padding: 2px;
}

.position_type>.input2 {
    width: 100%;
    display: flex;
}

.input2>label {
    display: inline-block;
    width: 70px;
    color: #fff;
    font-size: 14px;
    color: rgba(230, 230, 230, 1);
    font-size: 14px;
}

.input2>.input2_index {
    /* width: 100%; */
    flex: 1;
    height: 26px;
    display: flex;
}

.input2>.input2_index>.input2_index_div {
    flex: 1;
    position: relative;
}

.input2>.input2_index>.input2_index_div>input {
    width: 100%;
    height: 26px;
    background: rgba(28, 28, 29, 0.6);
    border-radius: 4px;
    border: 1px solid #3b3c40;
    margin-right: 0;
    color: rgba(230, 230, 230, 1);
    padding: 0 13px 0 11px;
    box-sizing: border-box;
}

.input2>.input2_index>.input2_index_div>span {
    position: absolute;
    right: 5px;
    top: 0;
    display: inline-block;
    /* width: 12px; */
    height: 26px;
    line-height: 26px;
    text-align: center;
    color: rgba(255, 255, 255, 0.5);
}

.input2>.input2_index>span {
    display: inline-block;
    width: 8px
}

.checkbox1 {
    width: 20px;
    height: 20px;
    box-sizing: border-box;
    margin-left: 10px;
    margin-top: 5px;
}

.checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
    border: 1px solid rgba(230, 230, 230, 0.4);
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.input2>.input2_index>.input2_index_div>input:hover {
    border: 1px solid rgba(44, 104, 247, 1);
}

.input2>.input2_index>.input2_index_div>input:focus {
    border: 1px solid #2c68f7;
}

.input_number::-webkit-outer-spin-button,
.input_number::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

.input_number[type="number"] {
    -moz-appearance: textfield;
}
</style>
